﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TKToXML.Models;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;

namespace TKToXML.Persistence.ClassMaps
{
    public class ToKhaiMap : ClassMapping<ToKhai>
    {
        public ToKhaiMap()
        {
            Table("EDTOKHAI"); 
            Id(x => x.Id, map => 
            {
                map.Column("So_TC");
                map.Generator(Generators.GuidComb);
            });
            Property(x => x.LoaiChungTu, map => map.Column("Loai_CT"));
            Property(x => x.NamChungTu, map => map.Column("Nam_CT"));
            Property(x => x.SoChungTu, map => map.Column("So_CT"));
            Property(x => x.NgayChungTu, map => map.Column("Ngay_CT"));
            Property(x => x.MaHQ, map => map.Column("Ma_HQ"));
            Property(x => x.MaLH, map => map.Column("Ma_LH"));            
            Property(x => x.NamDK, map => map.Column("NamDK"));
            Property(x => x.SoTK, map => map.Column("SoTK"));

            Property(x => x.NgayDK, map => map.Column("Ngay_DK"));
            Property(x => x.MaDonVi, map => map.Column("Ma_DV"));
            Property(x => x.TenDonViDoiTac, map => map.Column("Ten_DV_DT"));                        
            Property(x => x.MaNDUQ, map => map.Column("Ma_ND_UQ"));
            Property(x => x.MaCKXuat, map => map.Column("Ma_CK_X"));
            Property(x => x.TenCKXuat, map => map.Column("Ten_CK_X"));
            Property(x => x.MaCKNhap, map => map.Column("Ma_CK_N"));
            Property(x => x.TenCKNhap, map => map.Column("Ten_CK_N"));
            Property(x => x.MaPTVT, map => map.Column("Ma_PTVT"));
            Property(x => x.MaDKGH, map => map.Column("Ma_DK_GH"));
            Property(x => x.MaPTTT, map => map.Column("Ma_PTTT"));
            Property(x => x.MaNguyenTe, map => map.Column("Ma_NT"));
            Property(x => x.TyGiaNguyenTe, map => map.Column("TyGia_NT"));
            Property(x => x.TongSoKien, map => map.Column("Tong_SK"));
            Property(x => x.MaNuocXuatKhau, map => map.Column("Ma_NU_XK"));
            Property(x => x.MaNuocNhapKhau, map => map.Column("Ma_NU_NK"));
            Property(x => x.MaDonViCDGiaoHang, map => map.Column("Ma_DV_CD_GH"));
            Property(x => x.TenDonViCDGiaoHang, map => map.Column("TenDV_CD_GH"));
            Property(x => x.MaDonViGiaoHang, map => map.Column("Ma_DV_GH"));
            Property(x => x.TenDonViGiaoHang, map => map.Column("Ten_DV_GH"));
            Property(x => x.NoiGiaoHang, map => map.Column("NoiGH"));
            Property(x => x.MaDonViNganHang, map => map.Column("Ma_DV_NH"));
            Property(x => x.TenDonViNganHang, map => map.Column("Ten_DV_NH"));
            Property(x => x.MaDonViNganHang, map => map.Column("Ma_DV_NH"));
            Property(x => x.MaDonViNganHang, map => map.Column("Ma_DV_NH"));
            Property(x => x.MaDonViNganHang, map => map.Column("Ma_DV_NH"));
            Property(x => x.MaDonViNganHang, map => map.Column("Ma_DV_NH"));
            Property(x => x.MaDonViNganHang, map => map.Column("Ma_DV_NH"));
            Property(x => x.MaDonViNganHang, map => map.Column("Ma_DV_NH"));
            Property(x => x.MaDonViNganHang, map => map.Column("Ma_DV_NH"));

            //Bag(x => x.HopDongChiTiets, map =>
            //    {
            //        map.Table("EDHOPDDONGCT");
            //        map.Cascade(Cascade.All);
            //    }, 
            //    x => x.OneToMany(hdct => hdct.Class(typeof(HopDongChiTiet))));

            Bag(x => x.HopDongChiTiets, map =>
                {
                    map.Table("EDHOPDDONGCT");
                    map.Key(m => m.Column("HopDongId"));
                    map.Cascade(Cascade.All);
                    map.Inverse(true);
                },
                x => x.OneToMany(map => map.Class(typeof(HopDongChiTiet))));

        }
    }
}
